<template>
	<view class="container">
		<!-- 顶部自定义导航栏 -->
		<view class="navbar">
			<view class="title">试卷中心</view>
			<view class="icons">
				<view class="icon more"></view>
				<view class="icon circle"></view>
			</view>
		</view>
		<!-- Tab切换 -->
		<uni-segmented-control :current="tabIndex" :values="['固定试卷', '时段试卷']" @clickItem="tabIndex = $event.currentIndex" />
		<!-- 试卷列表 -->
		<uni-list>
			<uni-list-item v-for="paper in currentPaperList" :title="paper.name" :key="paper.id">
				<template #footer>
					<view>学科:{{ paper.subjectName }} 题量:{{ paper.questionCount }} 总分:{{ paper.score }}</view>
				</template>
			</uni-list-item>
		</uni-list>
	</view>
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import http from '../../http.js'
const tabIndex = ref(0)
const fixedPaper = ref([])
const timeLimitPaper = ref([])
async function fetchExamData() {
	const res = await http({ url: '/student/dashboard/index', method: 'post' })
	if (res && res.response) {
		fixedPaper.value = res.response.fixedPaper || []
		timeLimitPaper.value = res.response.timeLimitPaper || []
	}
}
const currentPaperList = computed(() => tabIndex.value === 0 ? fixedPaper.value : timeLimitPaper.value)
onMounted(fetchExamData)
</script>

<style scoped>
.container {
	background: #fafbfc;
	min-height: 100vh;
}

.navbar {
	width: 100%;
	height: 50px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 16px;
	background: #fff;
	border-bottom: 1px solid #f0f0f0;
}

.title {
	font-size: 20px;
	font-weight: bold;
	color: #222;
}

.icons {
	display: flex;
	align-items: center;
	gap: 12px;
}

.icon.more {
	width: 24px;
	height: 24px;
	border-radius: 50%;
	background: #eee;
	display: flex;
	align-items: center;
	justify-content: center;
}

.icon.circle {
	width: 24px;
	height: 24px;
	border-radius: 50%;
	border: 2px solid #222;
}

.tab-bar {
	display: flex;
	background: #fff;
	border-bottom: 1px solid #f0f0f0;
}

.tab {
	flex: 1;
	text-align: center;
	padding: 14px 0 10px 0;
	font-size: 16px;
	color: #888;
	position: relative;
}

.tab.active {
	color: #409eff;
	font-weight: bold;
}

.tab.active::after {
	content: '';
	display: block;
	width: 60%;
	height: 2px;
	background: #409eff;
	border-radius: 2px;
	position: absolute;
	left: 20%;
	bottom: 0;
}
</style>
